package vboot.core.module.mon.log.oper;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vboot.core.common.api.R;
import vboot.core.common.dao.JdbcDao;
import vboot.core.common.dao.Sqler;

@RestController
@RequiredArgsConstructor
@RequestMapping("mon/log/oper")
public class MonLogOperApi {

    @GetMapping
    public R get() {
        Sqler sqler = new Sqler("t.*", "mon_log_oper");
        sqler.addOrder("t.crtim desc");
        sqler.addLeftJoin("u.name as usena,u.usnam","sys_org_user u","u.id=t.useid");
        return R.ok(jdbcDao.findPageData(sqler));
    }

    @GetMapping("one/{id}")
    public R getOne(@PathVariable String id) {
        MonLogOper main = service.findOne(id);
        return R.ok(main);
    }

    @DeleteMapping("{ids}")
    public R delete(@PathVariable String[] ids) {
        return R.ok(service.delete(ids));
    }

    @DeleteMapping(value = "all")
    public R delAllInfoLog() {
        service.delAll();
        return R.ok();
    }

    @Autowired
    private JdbcDao jdbcDao;

    private final MonLogOperService service;

}
